<template>
	<view>
		<view v-if="isComment" class="mask" @click="handleShowPractical(0)"></view>
		<view class="comment-box">
			<view v-if="!isComment" class="exhibition-box w100 bg-white flex-x-around">
				<view class="input flex-x-between" @click="handleShowPractical(1, 0, 0)">
					<text class="iconfontPT iconxiepinglun comment"></text>
					<input placeholder="我来说两句" disabled type="text" value="" />
					<!-- <text class="iconfontPT iconbiaoqing smail-icon"></text> -->
				</view>
				<view :data-comment-number="commentNumber" class="comment-number inline-block relative">
					<text class="iconfontPT iconpinglun comment-icon"></text>
				</view>
				<text :class="{'iconfontPT like-icon': true, 'icondianzan-xuanzhong': isLike, 'icondianzan-weixuanzhong': !isLike }"
				 @click="handleLike"></text>
			</view>
			<view v-else class="practical-box w100 bg-white">
				<view class="flex-x-between header">
					<text class="cancel" @click="handleShowPractical(0)">取消</text>
					<text class="confirm" @click="handleComment(0)">发布</text>
				</view>
				<view class="body">
					<textarea placeholder="请输入回复内容" class="w100" :fixed="true" maxlength="300" cursor-spacing="20" :show-confirm-bar="false"
					 v-model="form.commentContent" confirm-type="send" auto-focus></textarea>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		addComment,
	} from '../../../apis/life-circle/index.js';

	export default {
		data() {
			return {
				puid: 0,
				pid: 0,
				isComment: false,
				form: {
					commentContent: ''
				},
				rules: {
					commentContent: [{
							required: true,
							message: '请输入回复内容',
						},
						{
							min: 1,
							max: 200,
							message: '回复内容字符长度在 1 到 200 个字符',
						}
					],
				}
			}
		},

		props: ['cid', 'commentNumber', 'isLike', 'callObject', 'm_pid', 'm_uid'],
		methods: {
			handleShowPractical(i, pid, puid) {
				this.pid = pid
				this.puid = puid
				this.isComment = !!i;
				!i && (this.form.commentContent = '')
			},
			handleComment() {
				let _this = this,
					params = {
						cid: this.cid,
						content: this.form.commentContent,
					}
				this.pid && (params.pid = this.pid)
				this.puid && (params.puid = this.puid)

				this.m_pid && (params.pid = this.m_pid)
				this.m_uid && (params.puid = this.m_uid)

				this.callObject && (params.content =
					`${params.content}//<span style="color: #E41805;">@${this.callObject.name}</span>：${this.callObject.content}`)

				this.$verification(this.form, this.rules, ok => {
					if (ok) {
						this.$loading.show()
						addComment(params).then(res => {
							_this.isComment = false;
							_this.$emit('updateComment');
							this.form.commentContent = '';
							this.$loading.hide()
						})
					}
				})
			},
			handleLike() {
				this.$emit('onSetLike')
			},
		},
	}
</script>

<style lang="less">
	.comment-box {
		.exhibition-box {
			box-shadow: 0rpx -2rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);
			height: 166rpx;
			position: fixed;
			bottom: 0%;
			right: 0;
			z-index: 1112;
			padding-bottom: 25px;
			box-sizing: border-box;

			.input {
				background: rgba(245, 245, 245, 1);
				border-radius: 50rpx;
				width: 465rpx;
				height: 78rpx;

				input {
					padding-left: 28rpx;
				}

				.comment {
					margin-left: 20rpx;
					color: #333333;
				}

				.smail-icon {
					font-size: 54rpx;
					margin-right: 20rpx;
				}
			}

			.comment-icon,
			.like-icon {
				font-size: 52rpx;
				color: #666666;
			}

			.like-icon {
				&.icondianzan-xuanzhong {
					color: #E41805;
				}
			}

			.comment-number {
				&::after {
					position: absolute;
					content: attr(data-comment-number);
					top: -12rpx;
					right: -20rpx;
					display: inline-block;
					padding: 10rpx 10rpx;
					font-size: 20rpx;
					background: #E41805;
					color: #ffffff;
					box-sizing: border-box;
					height: 35rpx;
					width: 35rpx;
					line-height: 17rpx;
					border-radius: 50rpx;
				}
			}
		}

		.practical-box {
			box-shadow: 0rpx -2rpx 8rpx 0rpx rgba(0, 0, 0, 0.1);
			height: 447rpx;
			position: fixed;
			bottom: 0%;
			right: 0;
			z-index: 1112;
			padding-bottom: 25px;
			box-sizing: border-box;

			.header {
				height: 107rpx;
				border-bottom: 1rpx solid rgba(197, 195, 195, .5);

				.cancel {
					padding-left: 30rpx;
				}

				.confirm {
					padding-right: 30rpx;
				}
			}

			.body {
				height: 253rpx;
				padding: 30rpx;
				box-sizing: border-box;

				textarea {
					max-height: 200rpx;
				}
			}
		}
	}
</style>
